var config = require('../../../utils/config');
var API_URL = config.API_URL;
var util = require('../../../utils/util');
var app = getApp();
var userInfo;
var getData = (that) => {
    let tag = that.data.tag;
    let url, list;
    if (tag == 1) {
        url = API_URL.next_first;
    } else {
        url = API_URL.next_second
    }
    util.PRL(url, {})
        .then(res => {
            console.log(res);
            if (tag == 1) {
                list = res.data.first;
            } else {
                list = res.data.second;
            }
            that.setData({
                list: list
            })
        }).catch(res => {
            console.log(res);
        })
}
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tag: 1
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        userInfo = my.getStorageSync({key:'user'});
        getData(this);
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },
    toggle: function (e) {
        let that = this;
        let tag = e.currentTarget.dataset.tag;
        if (that.data.tag == tag) {
            return
        }
        that.setData({
            tag: tag
        })
        getData(this);
    },
    info: function (e) {
        console.log(e);
        let index = e.currentTarget.dataset.index;
        let list = this.data.list;
        let id = list[index].userid;
        let name = list[index].username;
        wx.navigateTo({
            url: '/pages/user/next/info/info?id=' + id + '&name=' + name,
        })
    }
})